package com.waves.biz;

import com.waves.Constant;
import com.waves.anno.CacheDelete;
import com.waves.anno.CacheGet;
import com.waves.anno.CacheUpdate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

/**
 * @Description: 用户服务实现类
 **/

@Service
public class UserServiceImpl {

    @Resource
    private UserRepository userRepository;

    @CacheGet(id = "#id", prefix = Constant.USER_PREFIX)
    public User getUserById(Integer id) {
        return userRepository.getFromDB(id);
    }

    public User add(User user) {
        return userRepository.saveDB(user);
    }

    @CacheUpdate(id = "#user.id", prefix = Constant.USER_PREFIX)
    public User update(User user) {
        return userRepository.saveDB(user);
    }

    @CacheDelete(id = "#id", prefix = Constant.USER_PREFIX)
    public void remove(Integer id) {
        userRepository.removeFromDB(id);
    }
}
